package com.mframe.util;

import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.orm.hibernate3.SessionFactoryUtils;

/**
 * @author cuijr
 * @version 1.0
 * @since JDK 1.6
 * @category <p>OpenSessionInViewFilter是为了解决Struts中Session关闭</p>
 */
public class OpenSessionInViewFilter extends
		org.springframework.orm.hibernate3.support.OpenSessionInViewFilter {
	protected Session getSession(SessionFactory sf)
			throws DataAccessResourceFailureException {
		Session session = SessionFactoryUtils.getSession(sf, true);
		session.setFlushMode(FlushMode.COMMIT);

		return session;

	}
	protected void closeSession(Session s,SessionFactory sf){
		s.flush();
		super.closeSession(s, sf);
	}
}
